package com.xdf.docmanagementsystem.service.impl;

import com.xdf.docmanagementsystem.common.util.ConventUtil;
import com.xdf.docmanagementsystem.common.util.IOUtil;
import com.xdf.docmanagementsystem.service.ViewFile;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;

/**
 * @program: doc-management-system
 * @description:
 * @author: Zhang
 * @create: 2020-06-26 17:05
 **/
public class ViewExcelFileImpl implements ViewFile {
    @Override
    public synchronized void view(OutputStream os, File file) throws IOException {
        String path = file.getPath();
        File targetFile = new File(path + ".pdf");
        if (!targetFile.exists()) {
            targetFile.createNewFile();
            ConventUtil.excelToPDF(os, file.getPath(), targetFile.getPath());
        } else {
            IOUtil.writeFile(targetFile, os);
        }
    }
}
